<!--
 * @Description: svg 工程化组件
 * @Author: gaoyunpeng
 * @Date: 2022-01-18 21:48:56
 * @LastEditors: gaoyunpeng
-->
<template>
  <svg :class="svgClass" aria-hidden="true" v-on="$listeners">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component
export default class SvgIcon extends Vue {
  @Prop({ type: String, required: true }) iconClass!: string; // 证明一定有值
  @Prop({ type: String, default: '' }) className!: string;
  public get iconName() {
    return `#icon-${this.iconClass}`;
  }
  public get svgClass() {
    if (this.className) {
      return 'svg-icon ' + this.className;
    } else {
      return 'svg-icon';
    }
  }
}
</script>

<style scoped lang="scss">
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
